package com.ruoyi.eqmonitor.dispose.domain;

import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

/**
 * 设备监测时序数据
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("device_monitor_data")
public class ExteriorMonitorData {
    /**
     * 数据时间
     */
    private Date monitorTime;
    /**
     * 单位
     */
    private String dataUnit;
    /**
     * 监测指标
     */
    private String monitorCode;
    /**
     * 数据值
     */
    private Double monitorData;
    /**
     * 设备编码
     */
    private String snCode;
    /**
     * 设备类型
     */
    private String deviceType;
    /**
     * 监测指标名称
     */
    private String monitorName;
    /**
     * 设备类型名称
     */
    private String deviceTypeName;

    @TableField(value = "max(monitor_data)",
            insertStrategy = FieldStrategy.NEVER,
            updateStrategy = FieldStrategy.NEVER,
            select = false)
    private double maxData;

    /**
     * 构建Opentsdb数据
     */
    public static ExteriorMonitorData buildByOpentsdbTags(Date date, Double monitorData, OpentsdbTags opentsdbTags) {
        ExteriorMonitorData exteriorMonitorData = new ExteriorMonitorData();
        exteriorMonitorData.snCode = opentsdbTags.getSnCode();
        exteriorMonitorData.deviceType = opentsdbTags.getEquipmentTypeCode();
        exteriorMonitorData.monitorCode = opentsdbTags.getMonitorCode();
        exteriorMonitorData.monitorName = opentsdbTags.getMonitorName();
        exteriorMonitorData.deviceTypeName = opentsdbTags.getEquipmentType();
        exteriorMonitorData.monitorData = monitorData;
        exteriorMonitorData.dataUnit = opentsdbTags.getDataUnit();
        exteriorMonitorData.monitorTime = date;
        return exteriorMonitorData;
    }
}
